package com.neusoft.neuiotms.dcom.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractModel;
import com.neusoft.bizcore.web.jpa.model.Comment;
import com.neusoft.neuiotms.dcom.model.enums.HandoverStatus;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Entity
@org.hibernate.annotations.Table(appliesTo = "neuiot_handover", comment = "交接班表")
@Table(name = "neuiot_handover")
public class Handover extends AbstractModel {

    private static final long serialVersionUID = 1L;

    /** 所属组织名称 */
    @NotBlank(message = "组织名称不能为空")
    @Length(max = 255, message = "组织名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '组织名称'")
    private String orgName;

    /** 所属组织代码 */
    @NotBlank(message = "组织代码不能为空")
    @Length(max = 255, message = "组织代码不能超过{max}位")
    @Column(length = 255, nullable = false)
    private String orgCode;

    /** 交班时间 */
    @Column(length = 6, nullable = false)
    @Comment("datetime(6) NOT NULL COMMENT '交班时间'")
    private Date upTime;

    /** 交班人员名称 */
    @NotBlank(message = "交班人员名称不能为空")
    @Length(max = 255, message = "交班人员名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '交班人员名称'")
    private String upUserName;

    /** 交班人员编码 */
    @NotBlank(message = "交班人员编码不能为空")
    @Length(max = 255, message = "交班人员编码不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '交班人员编码'")
    private String upUserCode;

    /** 交班备注 */
    @NotBlank(message = "交班备注不能为空")
    @Length(max = 255, message = "交班备注不能超过{max}位")
    @Column(length = 255, nullable = false)
    private String upNote;

    /** 接班时间 */
    @Column(length = 6, nullable = true)
    @Comment("datetime(6) NULL DEFAULT NULL COMMENT '接班时间'")
    private Date downTime;

    /** 接班人员名称 */
    @Length(max = 255, message = "接班人员名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '接班人员名称'")
    private String downUserName;

    /** 接班人员编码 */
    @Length(max = 255, message = "接班人员编码不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '接班人员编码'")
    private String downUserCode;

    /** 接班备注 */
    @Length(max = 255, message = "接班备注不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL DEFAULT NULL COMMENT '接班人员编码'")
    private String downNote;

    /** 状态 */
    @Enumerated(EnumType.STRING)
    @Column(length = 12, nullable = true)
    @Comment("varchar(12) NULL COMMENT '状态'")
    private HandoverStatus status = HandoverStatus.created;

    /** 关联交接项记录值 */
    @OneToMany(mappedBy = "handover", fetch = FetchType.LAZY)
    @Cascade({CascadeType.ALL })
    private List<HandoverItemValue> items = new ArrayList<>();

    /** 关联职能组 */
    @ManyToOne
    FunctionalGroup functionalGroup;
}
